package com.blacktry.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.blacktry.entity.enums.OprLogConst;
import com.blacktry.entity.model.Classroom;
import com.blacktry.entity.model.ApiResult;
import com.blacktry.service.ClassroomService;
import com.blacktry.utils.ApiResultHandler;
import com.blacktry.utils.log.OperLog;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.bind.DefaultValue;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author blackTry
 * @since 2021-12-06
 */
@RestController
@Api(value = "教室管理模块", tags = "教室管理接口")
@RequestMapping("/classroom")
public class ClassroomController {
    @Autowired
    private ClassroomService classroomService;

//    @ApiOperation("修改教室状态")
//    @PutMapping("/update")
//    public ApiResult<?> updateWorkable(@RequestParam("id") Integer id,@RequestParam("flag") Integer flag){
//        return ApiResultHandler.buildApiResult(200,"成功",classroomService.updateWorkable(id,flag));
//    }

    @OperLog(operModul = "教室管理-修改教室信息",operType = OprLogConst.UPDATE,operDesc = "修改教室信息")
    @ApiOperation("修改教室信息")
    @PutMapping("/update")
    public ApiResult<Integer> update(@RequestBody Classroom classroom){
        return ApiResultHandler.buildApiResult(200,"成功",classroomService.updateClassroom(classroom));
    }

    @OperLog(operModul = "教室管理-查看适合的教室信息",operType = OprLogConst.SELECT,operDesc = "查看适合的教室信息")
    @ApiOperation("查看适合的教室信息")
    @PostMapping("/selectParam/{page}/{size}")
    public ApiResult<Map<Integer, List<Classroom>>> selectParam(@RequestBody Classroom classroom,@DefaultValue("1") @PathVariable("page") Integer page, @DefaultValue("6") @PathVariable("size") Integer size){
        Page<Classroom> classroomPage = new Page<>(page,size);
        return ApiResultHandler.buildApiResult(200,"成功",classroomService.selectParam(classroom,classroomPage));
    }

    @OperLog(operModul = "教室管理-查看教室是否被占用",operType = OprLogConst.SELECT,operDesc = "查看教室是否被占用")
    @ApiOperation("查看教室是否被占用")
    @PostMapping("/selectClassroom")
    public ApiResult<Boolean> selectClassroom(@RequestParam("id") Integer id,@RequestParam("classroom_id") Integer classroom_id){
        return ApiResultHandler.buildApiResult(200,"成功",classroomService.selectClassroom(id,classroom_id));
    }
}

